$("#form-customerClue-edit").validate({
	rules:{
		customerName:{
			required:true,
		},
		customerCellphone:{
			required:true,
		}
	},
	submitHandler:function(form){
		edit();
	}
});
/*
function edit() {
    _ajax_save(ctx + "module/customerClue/save", $('#form-customerClue-edit').serialize());
}*/

function edit() {
	var clueId = $("input[name='clueId']").val();
	var productType = $("select[name='productType']").val();						//线索产品类型
	var clueChannel = $("select[name='clueChannel']").val();						//线索来源渠道
	if(clueChannel == null){
		clueChannel = $("select[name='clueChannels']").val();
	}
	var customerName = $("input[name='customerName']").val();						//客户姓名
	var customerBackground = $("select[name='customerBackground']").val();			//客户背景
	if(customerBackground == null){
		customerBackground = $("select[name='customerBackgrounds']").val();
	}
	var customerCellphone = $("input[name='customerCellphone']").val();				//手机号码
	var customerSex = $("input[name='customerSex']:checked").val();							//性别
	var customerAge = $("input[name='customerAge']").val();							//年龄
	var customerEducation = $("select[name='customerEducation']").val();			//客户学历
	if(customerEducation == null){
		customerEducation = $("select[name='customerEducations']").val();
	}
	var customerBirth = $("input[name='customerBirth']").val();						//出生日期
	var customerJob = $("select[name='customerJob']").val();						//客户职业
	if(customerJob == null){
		customerJob = $("select[name='customerJobs']").val();
	}
	var customerIdentityNum = $("input[name='customerIdentityNum']").val();			//身份证号码
	var customerPhone = $("input[name='customerPhone']").val();						//电话号码
	var customerWechatAccount = $("input[name='customerWechatAccount']").val();		//微信号
	var customerEmergencyContact = $("input[name='customerEmergencyContact']").val();//紧急联系人
	var customerEmergencyCellphone = $("input[name='customerEmergencyCellphone']").val();//紧急联系人手机号码
	var customerProvince = $("select[name='customerProvince']").val();				//省
	var customerCity = $("select[name='customerCity']").val();						//市
	var customerArea = $("select[name='customerArea']").val();						//区
	var customerAddressDetail = $("input[name='customerAddressDetail']").val();		//详细地址
	
	var myreg=/^[1][3,4,5,7,8][0-9]{9}$/; //手机号码
	if(!myreg.test(customerCellphone)){
		layer.msg('请输入正确的手机号码')
		return false
	}else{
		$.ajax({
			cache : true,
			type : "POST",
			url : ctx + "module/customerClue/save",
			data : {
				"clueId": clueId,
				"productType": productType,
				"clueChannel": clueChannel,
				"customerName": customerName,
				"customerBackground": customerBackground,
				"customerCellphone": customerCellphone,
				"customerSex": customerSex,
				"customerAge": customerAge,
				"customerEducation": customerEducation,
				"customerBirth": customerBirth,
				"customerJob": customerJob,
				"customerIdentityNum": customerIdentityNum,
				"customerPhone": customerPhone,
				"customerWechatAccount": customerWechatAccount,
				"customerEmergencyContact": customerEmergencyContact,
				"customerEmergencyCellphone": customerEmergencyCellphone,
				"customerProvince": customerProvince,
				"customerCity": customerCity,
				"customerArea": customerArea,
				"customerAddressDetail": customerAddressDetail,
			},
			async : false,
			error : function(request) {
				$.modalAlert("系统错误", "error");
			},
			success : function(data) {
				if (data.code == 0) {
					parent.layer.msg("新增成功,正在刷新数据请稍后……",{icon:1,time: 500,shade: [0.1,'#fff']},function(){
						$.parentReload();
					});
				} else {
					$.modalAlert(data.msg, "error");
				}

			}
		});
	}

}

window.onload = function(){
	var cusType = $("input[id='cusType']").val();
	var s1 = $(".diss1");
	var s2 = $(".diss2");
	var s3 = $(".diss3");
	if(cusType == 13){
		$(s1).show();
		$(s2).hide();
		$(s3).hide();
	}else if(cusType == 14){
		$(s2).show();
		$(s1).hide();
		$(s3).hide();
	}else if(cusType == 15){
		$(s3).show();
		$(s2).hide();
		$(s1).hide();
	}else{
		$(s1).hide();
		$(s2).hide();
		$(s3).hide();
	}
}

$(function() {
	var html = "";
	$("#input_city").append(html);
	$("#input_area").append(html);
	$.each(pdata, function(idx, item) {
		if (parseInt(item.level) == 0) {
			html += "<option value='" + item.names + "' exid='" + item.code
					+ "'>" + item.names + "</option>";
		}
	});
	$("#input_province").append(html);
	$("#input_province").change(
			function() {
				if ($(this).val() == "")
					return;
				$("#input_city option").remove();
				$("#input_area option").remove();
				var code = $(this).find("option:selected").attr("exid");
				code = code.substring(0, 2);
				var html = "<option value=''>--请选择--</option>";
				$("#input_area").append(html);
				$.each(pdata, function(idx, item) {
					if (parseInt(item.level) == 1
							&& code == item.code.substring(0, 2)) {
						html += "<option value='" + item.names + "' exid='"
								+ item.code + "'>" + item.names + "</option>";
					}
				});
				$("#input_city").append(html);
			});
	$("#input_city").change(
			function() {
				if ($(this).val() == "")
					return;
				$("#input_area option").remove();
				var code = $(this).find("option:selected").attr("exid");
				code = code.substring(0, 4);
				var html = "<option value=''>--请选择--</option>";
				$.each(pdata, function(idx, item) {
					if (parseInt(item.level) == 2
							&& code == item.code.substring(0, 4)) {
						html += "<option value='" + item.names + "' exid='"
								+ item.code + "'>" + item.names + "</option>";
					}
				});
				$("#input_area").append(html);
			});
}); 